#include "stdio.h"


int check(char tq[20],int max)
{
	int i,j;
	j=max/2;
	for (i=1;i<=j;++i)
		if (tq[i]!=tq[max-i+1])	return 0;
	return 1;
}


main()
{
	int n;
	char tq[20],out[17];
	int i,j,max,s,y;
	scanf("%d",&n);
	while (n!=0)
	{
	    memset(out,0,sizeof(out));
	    for (i=2;i<=16;++i)
	    {
		memset(tq,0,sizeof(tq));
		s=n;
		max=0;
		while (s!=0)
		{
			++max;
			y=s%i;
			s=s/i;
			tq[max]=y;
		}
		if (check(tq,max)) 
		{
			out[i]=1;	
			out[0]=1;
		}
	    }
	    if (out[0]==0) printf("Number %d is not a palindrom\n",n);
	    else  	  
	    {
		    printf("Number %d is palindrom in basis",n);
		    for (i=2;i<=16;++i)
		    	if (out[i]==1) printf(" %d",i);
		    printf("\n");
	    }
	    scanf("%d",&n);
	}

}
